package com.fangcun.controller.admin.floor;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.admin.floor.FloorTeahouseSearchRequest;
import com.fangcun.bean.sys.PageBean;
import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProAffairException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.common.util.base.BaseAdminController;
import com.fangcun.entity.Floor;
import com.fangcun.entity.FloorReserve;
import com.fangcun.entity.FloorRoom;
import com.fangcun.entity.FloorRoomDetail;
import com.fangcun.entity.Teahouse;
import com.fangcun.service.admin.floor.FloorAdminService;

/**
 * @作者： 陳曉鬆 @时间： 2021年1月4日 - 上午10:06:25 @description：->
 */
@RestController
@RequestMapping("/admin/{version}/floor/auth")
public class FloorAdminController extends BaseAdminController {

	private static Logger LOG = LoggerFactory.getLogger(FloorAdminController.class);

	@Resource(name = "floorAdminService")
	private FloorAdminService floorAdminService;

	@ApiVersion(1.0)
	@RequestMapping("teahouse/list")
	private ResponseMsg teahouseList(@RequestBody PageBean<FloorTeahouseSearchRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.getParam().setId(getTeahouseId());
			msg.setData(floorAdminService.teahouseList(request));
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-获取茶楼列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-获取茶楼列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("teahouse/add")
	private ResponseMsg add(@RequestBody Teahouse request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.add(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-新增茶楼出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-新增茶楼异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("teahouse/update")
	private ResponseMsg update(@RequestBody Teahouse request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.update(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-修改茶楼出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-修改茶楼异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("floor/list")
	private ResponseMsg floorList(Long teahouseId) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(floorAdminService.floorList(teahouseId));
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-获取茶楼楼层房间列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-获取茶楼楼层房间列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("floor/add")
	private ResponseMsg floorAdd(@RequestBody Floor request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.floorAdd(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-新增茶楼楼层出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-新增茶楼楼层异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("floor/update")
	private ResponseMsg floorUpdate(@RequestBody Floor request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.floorUpdate(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-修改茶楼楼层出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-修改茶楼楼层异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("room/add")
	private ResponseMsg roomAdd(@RequestBody FloorRoom request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.roomAdd(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-新增茶楼房间出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-新增茶楼房间异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("room/update")
	private ResponseMsg roomUpdate(@RequestBody FloorRoom request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.roomUpdate(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-修改茶楼房间出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-修改茶楼房间异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("room/detail")
	private ResponseMsg roomDetail(Long roomId) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(floorAdminService.roomDetail(roomId));
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-房间详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-房间详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("room/detail/update")
	private ResponseMsg roomDetailUpdate(@RequestBody FloorRoomDetail request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.roomDetailUpdate(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-修改房间详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-修改房间详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("reserve/list")
	private ResponseMsg reserveList(@RequestBody PageBean<FloorReserve> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.getParam().setTeahouseId(getTeahouseId());
			msg.setData(floorAdminService.reserveList(request));
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-预定列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-预定列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("reserve/update")
	private ResponseMsg updateReserve(@RequestBody FloorReserve request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			floorAdminService.updateReserve(request);
		} catch (ProAffairException e) {
			LOG.error("-后台茶楼-修改预定出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台茶楼-修改预定异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
